//
//  AudioItem.swift
//  CatPomodoroTimer
//
//  Created by Xuri Li on 2024/8/3.
//

import SwiftUI

struct AudioItem: View {
    var noise: Noise
    var index: Int
    var onNoiseSelected: ((Noise, Int) -> Void)?
    var body: some View {
        Button(action: {
            ModelData.shared.selectedNoise(noise: noise)
            onNoiseSelected?(noise, index)
        }) {
            ZStack {
                Circle()
                    .fill(noise.isSelected ? Color(hex: 0xdfefff) : Color(hex: 0xf2f5f7)) // 根据状态改变颜色
                    .frame(minWidth: 100, minHeight: 100)
                    .padding(0)
                    .overlay {
                        Circle()
                            .stroke(noise.isSelected ? Color(hex: 0x1296db) : .clear , lineWidth: 2)
                    }
                    .padding(5)
                VStack {
                    Image(noise.imageName)
                        .resizable()
                        .scaledToFit()
                        .frame(width: 40)
                        .padding(4)
                    Text(noise.title)
                        .foregroundStyle(Color(hex: 0x1296db))
                        .font(.subheadline)
                }
            }
        }
        .buttonStyle(PlainButtonStyle()) // 使用 PlainButtonStyle 以保持自定义样式
    }
}

#Preview {
    AudioItem(noise: ModelData.shared.noises[0], index: 0)
}
